﻿// -------------------------------------------------------------------------------------------------------------------------------
// <copyright file="TestDecomposeByIncompleteLDLT.cs" company="Exul">
//     Copyright (c) Exul. All rights reserved.
// </copyright>
// <author>
//     Exul
// </author>
// -------------------------------------------------------------------------------------------------------------------------------

namespace ExulLibrary.Mathematics.LinearAlgebra.Sequential.Tests.CrcsSparseSymmetricMatrixTest.DoubleExtensions
{
    #region Usings

    using System.Diagnostics.CodeAnalysis;

    using ExulLibrary.Mathematics.LinearAlgebra.Sequential.DoubleExtensions;

    using NUnit.Framework;

    #endregion

    /// <summary>
    ///     Test suite for <see cref="CrcsSparseSymmetricMatrixExtensions.DecomposeByIncompleteLdlt"/>.
    /// </summary>
    [SuppressMessage(
        "Microsoft.Naming",
        "CA1709:IdentifiersShouldBeCasedCorrectly",
        MessageId = "LDLT",
        Justification = "LDLT is abbreviation of method name.")]
    [TestFixture]
    [Category("ExulLibrary.Mathematics.LinearAlgebra.Sequential.DoubleExtensions.CrcsSparseSymmetricMatrixExtensions")]
    public sealed class TestDecomposeByIncompleteLDLT
    {
        #region Methods

        #region public

        /// <summary>
        ///     Tests the method when the parameter is valid.
        /// </summary>
        [Test]
        public void WhenParameterIsValid()
        {
            // Arrange
            // Low triangle:
            // 1 0 0 0
            // 2 1 0 0
            // 3 0 1 0
            // 4 0 5 1
            // Diagonal:
            // 6 0 0 0
            // 0 7 0 0
            // 0 0 8 0
            // 0 0 0 9
            // Matrix:
            //  6 12  18  24
            // 12 31   0   0
            // 18  0  62 112
            // 24  0 112 305
            var matrix = new CrcsSparseSymmetricMatrix<double>(
                new[] { 0, 0, 1, 2, 4 },
                new[] { 0, 0, 0, 2 },
                new double[] { 6, 31, 62, 305 },
                new double[] { 12, 18, 24, 112 });

            // Act
            matrix.DecomposeByIncompleteLdlt();

            // Assert
            Assert.That(matrix.TriangleValues, Is.EquivalentTo(new double[] { 2, 3, 4, 5 }));
            Assert.That(matrix.DiagonalValues, Is.EquivalentTo(new double[] { 6, 7, 8, 9 }));
        }

        #endregion

        #endregion
    }
}